
import tensorflow as tf

from src.lstm.data_helper import hand_text
from src.lstm.config import Config
from src.lstm.tokenization import load_tokenizer
from src.lstm.model import build_model


tokenizer = load_tokenizer()
model = build_model()
# print(model.summary())

model.load_weights(Config.model_file)
graph = tf.get_default_graph()


def get_similay(text1, text2):
    with graph.as_default():
        input1 = hand_text(tokenizer, [text1])
        input2 = hand_text(tokenizer, [text2])
        res = model.predict([input1, input2])
    return res[0][0]


def get_similay_list(texts1, texts2):
    with graph.as_default():
        inputs1 = hand_text(tokenizer, texts1)
        inputs2 = hand_text(tokenizer, texts2)
        res = model.predict([inputs1, inputs2])
    return res